﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Text;

public partial class _SavePagesSuperC : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int i = 199;

        string url = @"http://www.superc.ca/fr/circulaire-accessible.html?method=getAccessibleFlyer&idFlyer=" + i.ToString();
        string localfilename = "C:\\SuperC" + i.ToString()+".txt";
    }

    static void GetUrl(Uri uri, string localFileName)
    {    
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);    
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();    
        try    
        {        
            // Hope GetEncoding() knows how to parse the CharacterSet
            Encoding encoding = Encoding.GetEncoding(response.CharacterSet);
            StreamReader reader = new StreamReader(response.GetResponseStream(), encoding);        
            using (StreamWriter sw = new StreamWriter(localFileName, false, encoding))        
            {            
                sw.Write(reader.ReadToEnd());            
                sw.Flush();            
                sw.Close();        
            }   
        }    
        finally    
        {        
            response.Close();    
        }
    }
}